

let url_id3 = parseInt((location.search).slice(-3));

$.ajax("./data/data2.json").then(function(res){
    var  res = JSON.parse(res).goods_list;
    $.each(res,function(index,item){
        if(url_id3 == item.goods_id){
            RenderDetail(item).then(function(){
                new Magnify();
                new Carts();
            });
            
            //console.log(111111)
            // alert("haha")
        }
        
    })
    
})




let url_id2 = parseInt((location.search).slice(-4));
// console.log(url_id);
$.ajax("./data/data1.json").then(function(res){
    var  res = JSON.parse(res).goods_list;
    $.each(res,function(index,item){
        if(url_id2 == item.goods_id){
            RenderDetail(item).then(function(){
                new Magnify();
                new Carts();
            });
            
            //console.log(111111)
            // alert("haha")
        }
        
    })
    
})




function RenderDetail(res){
    // console.log(res);
    // alert("进入函数")

    return new Promise((resolve,reject)=>{
        // console.log(res.goods_path);
        // console.log($(".cube"));
        // console.log($(".mz-magnify-wrap"));
        
        let html = `
    <div class="small-img">
        <img src=${res.goods_path}>
        <div class="cube"></div>
    </div>
    <div class="big-img">
        <img src=${res.goods_path}>
    </div>
    <div class="mz-infomation">
    <div class="mz-infor1">
    <h1 class="mz-infor1-title">${res.goods_name}</h1>
    <p class="mz-infor1-desc">${res.goods_detail}</p>
</div>
<div class="mz-infor2">
    <div class="sell-price">
        <em class="rmb">￥</em>
        <span class="count">${res.goods_price}</span>
    </div>
    <div>
        <span style="color: red">加购价</span>
        <span>另加19元起，即可换购超值商品</span>
        <span style="color: rosybrown">立即加购></span>
    </div>
    <div class="sell-service">支持&nbsp&nbsp&nbsp花呗分期&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp顺丰发货&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp七天无理由退换货</div>
</div>
<div class="sell-btn">
    <a class="instant-buy" href="http://localhost/seven/XDW/meizu_project/src/shopcart.html">立即购买</a>
    <a class="add-shopcart" data-id="${res.goods_id}">加入购物车</a>
</div>
</div>
</div>`;
$(".mz-magnify-wrap").html(html);
$(".phone-title-left").html(res.goods_name);
$(".cube").css({"background-image" : "url(" + res.goods_path + ")"});
resolve();
    })
    
}   